package com.zjeav.lingjiao.ui.presenter;

import com.zjeav.lingjiao.base.baseBean.BaseApplication;
import com.zjeav.lingjiao.base.baseBean.Result;
import com.zjeav.lingjiao.base.listener.CommonListener;
import com.zjeav.lingjiao.base.request.OrderSubscribeRequest;
import com.zjeav.lingjiao.base.response.OrderSubcribeResponse;
import com.zjeav.lingjiao.base.service.OrderSubscribeService;
import com.zjeav.lingjiao.base.tools.ObservableServiceTool;
import com.zjeav.lingjiao.base.tools.RetrofitInstance;
import com.zjeav.lingjiao.base.tools.SharedPreferencesUtils;
import com.zjeav.lingjiao.ui.book.BookDetailContract;

import io.reactivex.Observable;
import retrofit2.Retrofit;

public class ShopPresenter implements CommonListener{
    BookDetailContract.ShopView shopView;

    public ShopPresenter(BookDetailContract.ShopView shopView) {
        this.shopView = shopView;
    }
    public void getOder(OrderSubscribeRequest request){
        Retrofit retrofit= RetrofitInstance.getJsonTokenInstance();
        OrderSubscribeService service=retrofit.create(OrderSubscribeService.class);
        ObservableServiceTool.getResult((Observable)service.orderSubscribe(request),0,this);
    }


    @Override
    public void OnSuccess(Result result, int type) {
     if (type==0){
         if (result.getCode()==0){
             this.shopView.ShowShop((OrderSubcribeResponse) result.getData());
         }else {
             this.shopView.ShowError(null,result.getMessage());
         }

     }else if (type==1){

     }
    }

    @Override
    public void OnFailure(Throwable throwable, int type) {

    }
}
